package com.myk.game.heroscuffle.heroes;

import com.myk.game.heroscuffle.game.Attacked;
import com.myk.game.heroscuffle.game.Element;
import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.game.Sign;
import com.myk.game.heroscuffle.game.Skill;
import com.myk.game.heroscuffle.signs.CountSign;
import com.myk.game.heroscuffle.signs.CountSign_DongShang;
import com.myk.game.heroscuffle.skills.Skill_XueYin;
import com.myk.game.heroscuffle.utils.RdmPropUtil;

public class Hero_AoXue extends Hero {

    private static final int EXTRA_DAMAGE = 30;//攻击有冻伤标志的敌人时的额外伤害
    private static final int EXTRA_HEALING = 80;//攻击有两层冻伤标志的敌人时hp的恢复值

    public Hero_AoXue() {
        super("傲雪",
                "性格隐忍有仇必报，否则更愿意用技能防守。攻击有冻伤标记的敌人时移除该标记会有额外增益。",
                Element.ICE,
                1200, 165, 50,
                new Skill_XueYin());
    }

    @Override
    public void onAutoSelectAction() {
        //更加优先的反击敌人，没有敌人时，更加优先的使用主动技能雪隐
        Hero enemy = state.getAliveEnemy(); //获取仇人目标
        Skill xueyin = getUsableSkill(Skill_XueYin.class); //获取可用的雪隐技能
        Hero preAttacked = game.pool.getAnyoneAliveHero(this, enemy); //获取出了自己和敌人外的目标
        if (enemy != null) {
            if (xueyin != null) {
                if (RdmPropUtil.bingo(7, 13)) {
                    useSkill(xueyin);
                }
                else {
                    doAttackActionStart(new Attacked(enemy, "有仇必报奋力反击"));
                }
            }
            else {
                if (preAttacked != null) {
                    if (RdmPropUtil.bingo(11 / 13d)) {
                        doAttackActionStart(new Attacked(enemy, "有仇必报奋力反击"));
                    }
                    else {
                        doAttackActionStart(new Attacked(preAttacked, "一时疏忽失手攻击"));
                    }
                }
                else {
                    doAttackActionStart(new Attacked(enemy, "别无可选只能攻击"));
                }
            }
        }
        else { //没有enemy且还能继续攻击，此时preAttacked必然不为空
            if (xueyin != null) {
                if (game.pool.getAliveCount() >= 2) {
                    if (RdmPropUtil.bingo(8 / 13d)) {
                        useSkill(xueyin);
                    }
                    else {
                        doAttackActionStart(new Attacked(preAttacked, "略起杀心随机攻击"));
                    }
                }
                else {
                    if (RdmPropUtil.bingo(6 / 13d)) {
                        useSkill(xueyin);
                    }
                    else {
                        doAttackActionStart(new Attacked(preAttacked, "别无可选只能攻击"));
                    }
                }
            }
            else {
                if (game.pool.getAliveCount() >= 2) {
                    doAttackActionStart(new Attacked(preAttacked, "略起杀心随机攻击"));
                }
                else {
                    doAttackActionStart(new Attacked(preAttacked, "别无可选只能攻击"));
                }
            }
        }
    }

    @Override
    public void onAfterDoAttack(Hero attacked, int damage, boolean isToDeath) {
        if (!isToDeath) {
            CountSign dongSign = (CountSign) attacked.getSign(CountSign_DongShang.class);
            if (dongSign != null) {
                game.ui.printMsg("目标拥有" + dongSign.SIGN_NAME + "标记，" + attacked.getObviousName() + "额外");
                game.ui.sleepShortly();
                attacked.sufferDamage(null, null, dongSign, EXTRA_DAMAGE);
                if (dongSign.count == dongSign.SIGN_MAX) {
                    game.ui.printMsg(dongSign.SIGN_NAME + "标记有" + dongSign.SIGN_MAX + "层，" + getObviousName());
                    addHpWithPrint(EXTRA_HEALING);
                }
                game.ui.printMsg(attacked.getObviousName());
                attacked.removeSign(CountSign_DongShang.class);
            }
        }
    }
}
